package com.smartmedical.patient.video.service.lmpl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.smartmedical.common.core.domain.HealthR;
import com.smartmedical.patient.video.domain.dto.PatientVideoCountDto;
import com.smartmedical.patient.video.domain.entity.PatientVideoCommentEntity;
import com.smartmedical.patient.video.domain.entity.PatientVideoCountEntity;
import com.smartmedical.patient.video.domain.vo.PatientVideoCommentVo;
import com.smartmedical.patient.video.domain.vo.PatientVodeoVo;
import com.smartmedical.patient.video.mapper.VodeoMapper;
import com.smartmedical.patient.video.service.VodeoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: smart-medical
 * @BelongsPackage: com.smartmedical.patient.video.service.lmpl
 * @ClassName: VodeoServiceLMPL
 * @Author: zyn
 * @CreateTime: 2024-01-14  15:50
 * @Description: TODO
 */
@Service
@DS(value = "slave")
public class VodeoServiceLMPL implements VodeoService{

    @Autowired
    private VodeoMapper vodeoMapper;


    @Override
    public HealthR<List<PatientVodeoVo>> findVideoCategoryList() {

        List<PatientVodeoVo> list = vodeoMapper.findVideoCategoryList();


        return HealthR.ok(list);
    }

    @Override
    public void addVideoComment(int videoId, String content) {
        vodeoMapper.addVideoComment(videoId,content);
    }

    @Override
    public void addUserVideoCollection(Integer videoId) {


        List<PatientVideoCountDto> videoCountDto =vodeoMapper.fingVideoCount(videoId);

        for (PatientVideoCountDto countDto : videoCountDto) {


            if (countDto.getCollectionNum() == null) {
                countDto.setCollectionNum(1);
            } else {
                countDto.setCollectionNum(countDto.getCollectionNum() + 1);
            }

            countDto.setVideoId(videoId);
//            countDto.setCollectionNum(1);
            vodeoMapper.addUserVideoCollection(countDto);

        }


    }

    @Override
    public void videoBuy(Integer videoId, Integer price) {
        vodeoMapper.videoBuy(videoId,price);
    }

    @Override
    public HealthR<PatientVideoCommentVo> findVideoCommentList(Integer videoId) {


        PatientVideoCommentEntity patientVodeoVo= vodeoMapper.findVideoCommentList(videoId);
        PatientVideoCommentVo patientVideoCommentVo = new PatientVideoCommentVo();
        patientVideoCommentVo.setId(patientVodeoVo.getId());
        patientVideoCommentVo.setContent(patientVodeoVo.getContent());

        return HealthR.ok(patientVideoCommentVo);
    }
}
